/**
 * 语言检测功能测试文件
 * 用于验证设备语言检测是否正常工作
 */

// 模拟 uni-app 的 getSystemInfoSync 方法
const mockUni = {
  getSystemInfoSync: () => ({
    language: "en-US", // 可以修改这个值来测试不同语言
    locale: "en-US",
  }),
};

// 模拟全局 uni 对象
global.uni = mockUni;

// 导入语言检测函数
import { detectDeviceLanguage } from "../utils/language.js";

// 测试不同的设备语言设置
const testCases = [
  { input: "en-US", expected: "en", description: "英文（美国）" },
  { input: "en-GB", expected: "en", description: "英文（英国）" },
  { input: "vi-VN", expected: "vn", description: "越南语" },
  { input: "vi", expected: "vn", description: "越南语（简写）" },
  { input: "zh-CN", expected: "zh", description: "中文（简体）" },
  { input: "zh-TW", expected: "zh", description: "中文（繁体）" },
  { input: "ja-JP", expected: "zh", description: "日语（默认为中文）" },
  { input: "ko-KR", expected: "zh", description: "韩语（默认为中文）" },
  { input: "fr-FR", expected: "zh", description: "法语（默认为中文）" },
];

console.log("=== 语言检测功能测试 ===\n");

testCases.forEach((testCase) => {
  // 设置模拟的设备语言
  mockUni.getSystemInfoSync = () => ({
    language: testCase.input,
    locale: testCase.input,
  });

  // 执行检测
  const result = detectDeviceLanguage();

  // 输出结果
  const status = result === testCase.expected ? "✅ 通过" : "❌ 失败";
  console.log(
    `${status} ${testCase.description}: ${testCase.input} -> ${result} (期望: ${testCase.expected})`
  );
});

console.log("\n=== 测试完成 ===");
